#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <stdlib.h>
double findMedianSortedArrays(int* nums1, int nums1Size, int* nums2, int nums2Size) {
    int size = nums1Size + nums2Size;
    int flag_ret = 0;
    int flag = 1;
    if (size % 2 == 0)
        flag = 0;

    int cur1 = 0, cur2 = 0;
    int index = 0;
    double sum = 0;
    double ret = 0;
    while (cur1 < nums1Size && cur2 < nums2Size)
    {
        if (nums1[cur1] < nums2[cur2])
        {
            cur1++;
            index++;

            if (flag == 1 && index == size / 2 + 1)
            {
                ret = nums1[cur1 - 1];
                flag_ret = 1;

                break;
            }
            else if (flag == 0 && index == size / 2)
            {
                if (cur1 < nums1Size && nums1[cur1] < nums2[cur2])
                    sum = nums1[cur1] + nums1[cur1 - 1];
                else
                    sum = nums2[cur2] + nums1[cur1 - 1];

                ret = sum / 2;
                flag_ret = 1;

                break;
            }
        }
        else
        {
            cur2++;
            index++;

            if (flag == 1 && index == size / 2 + 1)
            {
                ret = nums2[cur2 - 1];
                flag_ret = 1;

                break;
            }
            else if (flag == 0 && index == size / 2)
            {
                if (cur2 < nums2Size && nums2[cur2] < nums1[cur1])
                    sum = nums2[cur2] + nums2[cur2 - 1];
                else
                    sum = nums1[cur1] + nums2[cur2 - 1];

                ret = sum / 2;
                flag_ret = 1;

                break;
            }
        }
    }

    while (cur1 < nums1Size)
    {
        cur1++;
        index++;

        if (flag == 1 && index == size / 2 + 1)
        {
            ret = nums1[cur1 - 1];
            break;
        }
        else if (flag == 0 && index == size / 2)
        {
            sum = nums1[cur1] + nums1[cur1 - 1];
            ret = sum / 2;

            break;
        }
    }
    while (cur2 < nums2Size)
    {
        cur2++;
        index++;

        if (flag == 1 && index == size / 2 + 1)
        {
            ret = nums2[cur2 - 1];
            break;
        }
        else if (flag == 0 && index == size / 2)
        {
            sum = nums2[cur2] + nums2[cur2 - 1];
            ret = sum / 2;

            break;
        }
    }

    return ret;
}

int Power(int num)
{
    int ret = 1;
    for (int i = 1; i <= num; i++)
        ret *= num;

    return ret;
}

int** generate(int numRows, int* returnSize, int** returnColumnSizes) {
    int** ret = (int**)malloc(sizeof(int*) * numRows);
    *returnColumnSizes = (int*)malloc(sizeof(int) * numRows);
    *returnSize = 0;

    for (int i = 0; i < numRows; i++)
    {
        returnColumnSizes[*returnSize] = i + 1;
        ret[(*returnSize)++] = (int*)malloc(sizeof(int) * (i + 1));

        for (int j = 0; j <= i; j++)
        {
            ret[i][j] = Power(i) / (Power(i - j) * Power(j));
        }
    }

    return ret;
}

int main()
{
    //int nums1[1] = { 1 };
    //int nums2[1] = { 1 };
    //double ret = findMedianSortedArrays(nums1, 1, nums2, 1);

    //printf("%d\n", ret);

    int retusize = 0;
    int* retcol;
    generate(1, &retusize, &retcol);

    return 0;
}